using System;
using System.Data;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CheckBoxListPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();            
        }
    }
    void LoadData()
    {
        string connectionString =
                WebConfigurationManager.ConnectionStrings[
                "RCVDB2000"].ConnectionString;

        ControlHelper cls = new
        ControlHelper(connectionString);
        cls.CommandText = 
        "select * from tblJobCategories";
        cls.CommandType = CommandType.Text;
        cls.InitProperties();
        cls.FillDataTableToCheckBoxList(
        this.CheckBoxList1, 
        "JobCategoryName", "JobCategoryID", "2");
        
        cls.FillArrayListToCheckBoxList(
        this.CheckBoxList2, "None", "", "");
        cls.Finalize();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Literal1.Text="";
        foreach(ListItem listItem in 
        CheckBoxList1.Items)
        {
            if (listItem.Selected)
                Literal1.Text += listItem.Value 
                + "-" + listItem.Text +"<br>";
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Literal2.Text = "";
        foreach (ListItem listItem in 
        CheckBoxList2.Items)
        {
            if(listItem.Selected)
                Literal2.Text += listItem.Value
                + "-" + listItem.Text + "<br>";
        }
    }
}
